package com.itheima.health;

import com.itheima.health.utils.redis.RedisUtil;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@SpringBootTest
@SpringBootApplication
public class RedisDemo {



    @Test
    public  void test2(){
        RedisTemplate<Object, Object> template = RedisUtil.getInstance();
        //  设置redis存储数据 过期时间
         template.opsForValue().set("heima","a.jpg",10, TimeUnit.SECONDS);


        boolean flag =  template.opsForValue().setIfAbsent("checkitem id","hello",20,TimeUnit.SECONDS);
        System.out.println(flag);
    }



    @Test
    public  void test1(){
        RedisTemplate<Object, Object> template = RedisUtil.getInstance();

        //   redis 存储set集合
        template.opsForSet().add("myset","tom","marry");

        //  redis  集合 set  移除指定的数据
        template.opsForSet().remove("myset","tom");

        //  查询所有set集合 元素
        Set<Object> myset = template.opsForSet().members("myset");

        System.out.println(myset);



    }
}










